#ifndef __UPDATE_H__
#define __UPDATE_H__

// Includes
#include <PA9.h>       // Include for PA_Lib

#include "Init.h"
#include "Boost.h"
#include "Chests.h"
#include "Guage.h"
#include "Avatar.H"
#include "DisplayText.h"

void gameUpdate()
{
//INCREASE STAMINA
//-----------------------------------------------------------
//-----------------------------------------------------------
	//increase stamina while resting
	//if a second has passed (1000 milliseconds)
	if(((staminaSeconds + 1)*1000) <= Tick(staminaClock))
	{	
		staminaSeconds++;
		//if the required number of seconds have passed
		if((staminaSeconds % staminaRestore) == 0)
		{
			player.increaseStamina(staminaBoost);
		}
	}

//UPDATE GUAGES	
//-----------------------------------------------------------
//-----------------------------------------------------------
	//update Guages
	currentHPDisplay();
	currentStaminaDisplay();
	currentSpecialDisplay();
	
//CHECK FOR SPRITES BEING TOUCHED	
//-----------------------------------------------------------
//-----------------------------------------------------------	
	for(counter = 0; counter < NUMBER_OF_SPRITES; counter++)
	{
		if(PA_SpriteTouched(counter))
		{
			//turn touch sprite to true
			touchSprite = true;
			
			switch(counter)
			{
			case 0:
				//Do nothing
				//Avatar
				break;
			case 1:
				//HP stone
				useHPStone();
				break;
			case 2:
				//Stamina stone
				useStaminaStone();
				break;
			case 3:
				//Attack stone
				useAttackStone();
				break;
			case 4:
				//Defense stone
				useDefenseStone();
				break;
			case 5:
				//Special stone
				useSpecialStone();
				break;
			case 6:
				//chest one - hp stone
				chestOne();
				break;
			case 7:
				//chest two - stamina stone
				chestTwo();
				break;
			case 8:
				//chest three - attack stone
				chestThree();
				break;
			case 9:
				//chest four - defense stone
				chestFour();
				break;
			case 10:
				//chest five - special stone
				chestFive();
				break;
			case 11:
				//reserved for button
				break;
			case 12:
				//reserved for button
				break;
			case 13:
				//reserved for HP guage
				break;
			case 14:
				//reserved for Stamina guage
				break;
			case 15:
				//reserved for Special guage
				break;
				
			default:
				break;
			}
		}
		//reset touchSprite in case it was set to 'true'
		touchSprite = false;
	}
	
//RECHARGE STONES	
//-----------------------------------------------------------
//-----------------------------------------------------------	
	//if recharging hp stone
	if(hpRecharge == true)
	{
		chargeHPStone();
	}
	
	//if recharging stamina stone
	if(stamRecharge == true)
	{
		chargeStaminaStone();
	}
	
	//if recharging attack stone
	if(attRecharge == true)
	{
		chargeAttackStone();
	}
	
	//if recharging defense stone
	if(defRecharge == true)
	{
		chargeDefenseStone();
	}
	
	//if recharging special stone
	if(specRecharge == true)
	{
		chargeSpecialStone();
	}
	
	
//CLEAN UP KICK ANIMATION	
//-----------------------------------------------------------
//-----------------------------------------------------------	
	if((isKicked == true) && (kickInc <= Tick(kickClock)))
	{
monKick = false;
		//stop kick to left
		if((kickNum == 1) && (PA_GetSpriteAnimFrame(0, avSprNo) == 43))
		{
			PA_StopSpriteAnim (0, avSprNo);
			PA_SetSpriteAnim(0, avSprNo, 7);
			isKicked = false;
		}
		
		if((kickNum == 2) && (PA_GetSpriteAnimFrame(0, avSprNo) == 47))
		{
			PA_StopSpriteAnim (0, avSprNo);
			PA_SetSpriteAnim(0, avSprNo, 7);
			isKicked = false;
		}
		
		if((kickNum == 3) && (PA_GetSpriteAnimFrame(0, avSprNo) == 50))
		{
			PA_StopSpriteAnim (0, avSprNo);
			PA_SetSpriteAnim(0, avSprNo, 7);
			isKicked = false;
		}
		
		//stop kick to right
		if((kickNum == 1) && (PA_GetSpriteAnimFrame(0, avSprNo) == 32))
		{
			PA_StopSpriteAnim (0, avSprNo);
			PA_SetSpriteAnim(0, avSprNo, 0);
			isKicked = false;
		}
		
		if((kickNum == 2) && (PA_GetSpriteAnimFrame(0, avSprNo) == 36))
		{
			PA_StopSpriteAnim (0, avSprNo);
			PA_SetSpriteAnim(0, avSprNo, 0);
			isKicked = false;
		}
		
		if((kickNum == 3) && (PA_GetSpriteAnimFrame(0, avSprNo) == 39))
		{
			PA_StopSpriteAnim (0, avSprNo);
			PA_SetSpriteAnim(0, avSprNo, 0);
			isKicked = false;
		}
	}


//CLEAN UP SHOT ANIMATION	
//-----------------------------------------------------------
//-----------------------------------------------------------
	if((isShot == true) && ((shotTime + shotInc) <= Tick(gameClock)))
	{
		//left
		if(PA_GetSpriteAnimFrame(0, avSprNo) == 28)
		{
			PA_StopSpriteAnim (0, avSprNo);
			PA_SetSpriteAnim(0, avSprNo, 7);
			isShot = false;
		}
		
		//right
		if(PA_GetSpriteAnimFrame(0, avSprNo) == 24)
		{
			PA_StopSpriteAnim (0, avSprNo);
			PA_SetSpriteAnim(0, avSprNo, 0);
			isShot = false;
		}
	}




//DISPLAY MENUS ON TOPSCREEN
//-----------------------------------------------------------
//-----------------------------------------------------------
//display controls menu
	if(selectCount == 0)
	{
		//no updates
	}
	else if (selectCount == 1)
	{
		//UPDATE FACIAL EXPRESSION AND TEXT SPRITES
		
		//display different facial expression based on percent of health
		//660 = 66.0%
		if(player.calculateCurrentHP() >= 330)
			PA_SetSpriteAnim(1, 4, 17);
		else if (player.calculateCurrentHP() < 330)
			PA_SetSpriteAnim(1, 4, 27);
			
		if(player.calculateCurrentHP() >= 660)	
			PA_SetSpriteAnim(1, 5, 18);
		else if(player.calculateCurrentHP() >= 330)
			PA_SetSpriteAnim(1, 5, 25);
		else if(player.calculateCurrentHP() < 330)
			PA_SetSpriteAnim(1, 5, 28);
			
	
		if(player.calculateCurrentHP() >= 330)
			PA_SetSpriteAnim(1, 8, 21);
		else if (player.calculateCurrentHP() < 330)
			PA_SetSpriteAnim(1, 8, 29);
			
		if(player.calculateCurrentHP() >= 660)	
			PA_SetSpriteAnim(1, 9, 22);
		else if(player.calculateCurrentHP() >= 330)
			PA_SetSpriteAnim(1, 9, 26);
		else if(player.calculateCurrentHP() < 330)
			PA_SetSpriteAnim(1, 9, 30);
		

		
		//level
		displayText(1, 12, player.getLevel(), 10);
		displayText(1, 13, player.getLevel(), 1);
		//exp
		//right align
		if(player.getExp() < 100)
		{
			displayText(1, 14, player.getExp(), 10);
			displayText(1, 15, player.getExp(), 1);
		}
		else if(player.getExp() < 1000)
		{
			displayText(1, 14, player.getExp(), 100);
			displayText(1, 15, player.getExp(), 10);
			displayText(1, 16, player.getExp(), 1);
		}
		else if(player.getExp() < 10000)
		{
			displayText(1, 14, player.getExp(), 1000);
			displayText(1, 15, player.getExp(), 100);
			displayText(1, 16, player.getExp(), 10);
			displayText(1, 17, player.getExp(), 1);
		}
		else
		{
			displayText(1, 14, player.getExp(), 10000);
			displayText(1, 15, player.getExp(), 1000);
			displayText(1, 16, player.getExp(), 100);
			displayText(1, 17, player.getExp(), 10);
			displayText(1, 18, player.getExp(), 1);
		}
		//current hp
		displayText(1, 19, player.getCurrentHP(), 100);
		displayText(1, 20, player.getCurrentHP(), 10);
		displayText(1, 21, player.getCurrentHP(), 1);
		//max hp
		displayText(1, 22, player.getMaxHP(), 100);
		displayText(1, 23, player.getMaxHP(), 10);
		displayText(1, 24, player.getMaxHP(), 1);
		//current stamina
		displayText(1, 25, player.getCurrentStamina(), 100);
		displayText(1, 26, player.getCurrentStamina(), 10);
		displayText(1, 27, player.getCurrentStamina(), 1);
		//max stamina
		displayText(1, 28, player.getMaxStamina(), 100);
		displayText(1, 29, player.getMaxStamina(), 10);
		displayText(1, 30, player.getMaxStamina(), 1);
		//current special
		displayText(1, 31, player.getCurrentSpecial(), 100);
		displayText(1, 32, player.getCurrentSpecial(), 10);
		displayText(1, 33, player.getCurrentSpecial(), 1);
		//max special
		displayText(1, 34, player.getMaxSpecial(), 100);
		displayText(1, 35, player.getMaxSpecial(), 10);
		displayText(1, 36, player.getMaxSpecial(), 1);
		//attack
		displayText(1, 37, player.getCurrentAttack(), 100);
		displayText(1, 38, player.getCurrentAttack(), 10);
		displayText(1, 39, player.getCurrentAttack(), 1);
		//defense
		displayText(1, 40, player.getCurrentDefense(), 100);
		displayText(1, 41, player.getCurrentDefense(), 10);
		displayText(1, 42, player.getCurrentDefense(), 1);
	}
	else if (selectCount == 2)
	{
		//UPDATE STONES EQUIPPED
		
		if(stoneOneEquip == true)
		{
			PA_SetSpriteAnim(1, 43, 43);
			PA_SetSpriteAnim(1, 44, 44);
			PA_SetSpriteAnim(1, 45, 45);
			PA_SetSpriteAnim(1, 46, 46);
		}
		
		if(stoneTwoEquip == true)
		{
			PA_SetSpriteAnim(1, 47, 47);
			PA_SetSpriteAnim(1, 48, 48);
			PA_SetSpriteAnim(1, 49, 49);
			PA_SetSpriteAnim(1, 50, 50);
		}
		
		if(stoneThreeEquip == true)
		{
			PA_SetSpriteAnim(1, 51, 51);
			PA_SetSpriteAnim(1, 52, 52);
			PA_SetSpriteAnim(1, 53, 53);
			PA_SetSpriteAnim(1, 54, 54);
		}
		
		if(stoneFourEquip == true)
		{
			PA_SetSpriteAnim(1, 55, 55);
			PA_SetSpriteAnim(1, 56, 56);
			PA_SetSpriteAnim(1, 57, 57);
			PA_SetSpriteAnim(1, 58, 58);
		}
		
		/*
		if(stoneFiveEquip == true)
		{
			PA_SetSpriteAnim(1, 59, 59);
			PA_SetSpriteAnim(1, 60, 60);
			PA_SetSpriteAnim(1, 61, 61);
			PA_SetSpriteAnim(1, 62, 62);
		}
		*/
		
	}
	else if (selectCount == 3)
	{
	/*
		PA_SetSpriteAnim(1, 0, 0);
		PA_SetSpriteAnim(1, 1, 0);
		PA_SetSpriteAnim(1, 2, 0);
		PA_SetSpriteAnim(1, 3, 0);
		PA_SetSpriteAnim(1, 4, 0);
		PA_SetSpriteAnim(1, 5, 0);
		PA_SetSpriteAnim(1, 6, 0);
		PA_SetSpriteAnim(1, 7, 0);
		PA_SetSpriteAnim(1, 8, 0);
		PA_SetSpriteAnim(1, 9, 0);
		PA_SetSpriteAnim(1, 10, 0);
		PA_SetSpriteAnim(1, 11, 0);
		*/
	}
	
}

#endif  //__UPDATE_H__
